package com.winsomely.leecode;

/**
 * 最小操作次数使数组元素相等
 * 
 * @author liujiawei
 *
 */
public class MinMoves {

	public int minMoves(int[] nums) {
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < nums.length; i++) {
			min = Math.min(min, nums[i]);
		}
		int s = 0;
		for (int i = 0; i < nums.length; i++) {
			s += nums[i] - min;
		}
		return s;
	}

	public static void main(String[] args) {
		MinMoves t = new MinMoves();
		int[] nums = { 1, 2, 3, 4, 9, 23, 67, 9, 23, 567, 2, 3 };
		System.out.println(t.minMoves(nums));
	}

}
